﻿using System;
using System.Windows;
using System.Collections;
using System.Collections.ObjectModel;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace PuzzleDiamonds
{
    public class Scene
    {
        protected Canvas m_sceneCanvas;
        protected Collection<SceneObject> m_sceneObjects = new Collection<SceneObject>();

        public Canvas SceneCanvas
        {
            get { return m_sceneCanvas; }
        }

        public Scene(Canvas pSceneCanvas)
        {
            m_sceneCanvas = pSceneCanvas;
        }

        public void AddObject(SceneObject pObject)
        {
            m_sceneObjects.Add(pObject);

            Visual visualObject = pObject.GetVisualObject();
            if (visualObject != null)
                m_sceneCanvas.Children.Add(visualObject);
        }

        public void RemoveObject(SceneObject pObject)
        {
            m_sceneObjects.Remove(pObject);

            Visual visualObject = pObject.GetVisualObject();
            if (visualObject != null)
                m_sceneCanvas.Children.Remove(visualObject);
        }

        public void RemoveAllObjects()
        {
            m_sceneObjects.Clear();
            m_sceneCanvas.Children.Clear();
        }

        public bool ExistObject(SceneObject pObject)
        {
            return (m_sceneObjects.IndexOf(pObject) >= 0);
        }

        public void Update(double pTick)
        {
            int i = 0;
            while (i < m_sceneObjects.Count)
            {
                m_sceneObjects[i].Update(pTick);
                i++;
            }
        }
    }
}
